package com.example.base.net

import com.example.base.entity.*
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.HTTP
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query

interface ApiServer {
    //验证码登录
    @POST(Const.LOGIN_CODE_URL)
    suspend fun loginCode(@Body body: RequestBody): LoginEntityResult

    //发送验证码
    @POST(Const.CODE_URL)
    suspend fun sendCode(@Query("phone") phone: String): CodeEntityResult

    @GET(Const.USERINFO_URL)
    suspend fun userInfo(): UserInfoEntityResult

    @POST(Const.PASSWORD_URL)
    suspend fun password(@Body body: RequestBody): PasswordEntityResult

    @POST(Const.LOGIN_URL)
    suspend fun login(@Body body: RequestBody): LoginEntityResult

    @GET(Const.INDEX_URL)
    suspend fun index(): IndexEntityResult

    //优惠券
    @GET(Const.COUPON_URL)
    suspend fun coupon(
        @Query("limit") limit: String,
        @Query("page") page: String,
        @Query("type") type: String
    ): CouponEntityResult

    @POST(Const.GETCOUPON_URL)
    suspend fun getCoupon(@Body body: RequestBody): GetCouponEntityResult

    //搜索
    @GET(Const.SEARCH_URL)
    suspend fun search(
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): GoodsEntityResult

    @GET(Const.GOODS_INDEX_URL)
    suspend fun goodsIndex(
        @Path("type") type: Int,
        @Query("limit") limit: Int,
        @Query("page") page: Int
    ): GoodsEntityResult

    @GET(Const.XQ_URL)
    suspend fun xq(@Path("id") id: Int, @Query("type") type: String): GoodsDetailEntityResult

    @GET(Const.YX_URL)
    suspend fun yx(): GoodsEntityResult

    @POST(Const.SAVE_URL)
    suspend fun save(@Body body: RequestBody): SaveEntityResult

    @GET(Const.CAR_URL)
    suspend fun car(
        @Query("isValid") isValid: String,
        @Query("limit") limit: String,
        @Query("page") page: String
    ): CarEntityResult

    @POST(Const.UPDATE_URL)
    suspend fun update(@Query("id") id: Int, @Query("number") number: Int): UpdateEntityResult

    @POST(Const.DELETE_URL)
    suspend fun delete(@Query("ids") ids: Array<Int>): DeleteEntityResult

    @GET(Const.CATEGORY_URL)
    suspend fun category(): CategoryEntityResult//一级分类二级分类数据均在这里，只需请求一次

    @GET(Const.CATEDETAIL_URL)
    suspend fun cateDetail(
        @Query("cid") cid: Int,
        @Query("keyword") keyword: String,
        @Query("limit") limit: Int,
        @Query("news") news: Boolean,
        @Query("page") page: Int,
        @Query("priceOrder") priceOrder: String,
        @Query("salesOrder") salesOrder: String
    ): GoodsEntityResult

    @GET(Const.COMMENT_URL)
    suspend fun comment(@Path("id")id:Int,@Query("limit")limit:Int,@Query("page")page:Int,@Query("type")type:String):CommentEntityResult
    @POST(Const.PREORDER_URL)
    suspend fun preOrder(@Body body:ParamPreOrder):PreOrderEntityResult
    @GET(Const.GETPREORDER_URL)
    suspend fun getPreOrder(@Path("preOrderNo")preOrderNo:String):GetPreOrderEntityResult
    @POST(Const.ORDER_URL)
    suspend fun order(@Body body:ParamOrder):OrderEntityResult
    @POST(Const.PAY_URL)
    suspend fun pay(@Body body:ParamPay):PayEntityResult



    //视频中的请求
    @GET(Const.BANNER_VIDEO_URL)
    suspend fun bannerVideo(): BannerVideoEntityResult

    @GET(Const.TYPE_VIDEO_URL)
    suspend fun typeVideo(): TypeVideoEntityResult

    @GET(Const.VIDEO_URL)
    suspend fun video(
        @Query("channelId") channelId: String,
        @Query("page") page: Int,
        @Query("pagesize") pagesize: Int
    ): VideoEntityResult

    //演示delete用法
    @HTTP(method = "DELETE", path = Const.DELETE_URL, hasBody = true)
    suspend fun nosc(@Body body: RequestBody): SaveEntityResult

    //智慧园区
    @GET(Const.NEWS_URL)
    suspend fun news(): NewsEntityResult

    @GET(Const.NEWS_DETAIL_URL)
    suspend fun newsDetail(@Path("id") id: Int): NewsDetailEntityResult

    @PUT(Const.NEWS_UPDATE_URL)
    suspend fun updateNews(@Path("id") id: Int, @Body body: ParamNews): NewsDetailEntityResult
}